// app/model/operation_log_model.js
'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE, TEXT } = app.Sequelize;

  const OperationLog = app.model.define('operation_log', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    userId: {
      type: INTEGER,
      allowNull: false,
      comment: '用户ID'
    },
    userName: {
      type: STRING(50),
      allowNull: false,
      comment: '用户姓名'
    },
    action: {
      type: STRING(100),
      allowNull: false,
      comment: '操作动作'
    },
    module: {
      type: STRING(50),
      allowNull: false,
      comment: '操作模块'
    },
    description: {
      type: STRING(200),
      allowNull: true,
      comment: '操作描述'
    },
    ip: {
      type: STRING(45),
      allowNull: true,
      comment: 'IP地址'
    },
    userAgent: {
      type: STRING(255),
      allowNull: true,
      comment: '用户代理'
    },
    requestData: {
      type: TEXT,
      allowNull: true,
      comment: '请求数据'
    },
    responseData: {
      type: TEXT,
      allowNull: true,
      comment: '响应数据'
    }
  }, {
    tableName: 'operation_logs',
    underscored: true,
    comment: '操作日志表'
  });

  return OperationLog;
};